<!doctype html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <title>注册</title>
    <meta content="width=device-width,initial-scale=1" name="viewport">
    <link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/@mdi/font@5.x/css/materialdesignicons.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css" rel="stylesheet">
    <link rel="shortcut icon" href="./img/logo.png" type="image/x-icon">
    <style type="text/css">
        .login-box {
            box-shadow: 2px 2px 5px #9fa5af;
            min-width: 20vw;
            padding: 1.5em;
            border-radius: 17px;
            color: hsla(0, 0%, 100%, .7);
            z-index: 1;
            background-color: white;
        }
        canvas {
            height: 100%;
            left: 0;
            position: fixed;
            top: 0;
            touch-action: none;
            width: 100%;
        }
    </style>
</head>
<body>
<canvas></canvas>
<div id="app">
    <v-app>
        <template>
            <img src="img/slogan.png" style="max-width: 30vw; position: fixed">
            <div class="login-box mx-auto my-auto">
                <v-form
                    @submit.prevent="login"
                    ref="form"
                    v-model="valid"
                >
                    <v-text-field
                        label="账户"
                        v-model="form.username"
                        clearable
                        autofocus
                    ></v-text-field>
                    <v-text-field
                        :append-icon="showPassword ? 'mdi-eye':'mdi-eye-off'"
                        @click:append="showPassword = !showPassword"
                        :type="showPassword ? 'text' : 'password'"
                        label="密码"
                        v-model="form.password"
                        :rules="passwordRules"
                        clearable
                    ></v-text-field>
                    <v-text-field
                        :append-icon="showPassword ? 'mdi-eye':'mdi-eye-off'"
                        @click:append="showPassword = !showPassword"
                        :type="showPassword ? 'text' : 'password'"
                        label="确认密码"
                        v-model="form.confirmPassword"
                        :rules="[v => v === form.password]"
                        clearable
                    ></v-text-field>
                    <v-btn
                        :disabled="!valid"
                        type="submit"
                        color="blue"
                        outlined
                        block
                    >
                        注册
                    </v-btn>
                </v-form>
            </div>
        </template>
    </v-app>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.js"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
    new Vue({
        el: '#app',
        vuetify: new Vuetify(),
        data: {
            valid: true,
            form: {
                password: '',
                confirmPassword:''
            },
            passwordRules: [
                v => !!v || '需要密码'
            ],
            showPassword: false
        },
        methods: {
            login() {
                axios
                    .post('/api/sign_in', this.form, {timeout: 5000})
                    .then(response => {
                        if (response.status === 200) {
                            window.open('main.html', '_self')
                        }
                    })
            }
        }
    })
</script>
<script src="login_bg.js"></script>
</body>
</html>